package ebj.common.compress;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.compress.compressors.gzip.GzipUtils;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.google.common.base.Charsets;

public class CompressTest {
	static String accessKey = "AKIAIIRBULVIK2HAJF6A";
    static String secretKey = "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";
    
    public static void main(String[] args) throws IOException {
        System.out.println(GzipUtils.isCompressedFilename("a.gz"));
        System.out.println(GzipUtils.getCompressedFilename("key_md5"));
        System.out.println(GzipUtils.getUncompressedFilename("key_md5.gz"));
        System.out.println(GzipUtils.getUncompressedFilename("key_md5"));
        
        // String url = "http://track.ymdruid.com/report?report_param={\"data\":[\"clicks\"],\"filters\":{\"$and\":{\"campaign_id\":{\"$eq\":201405}}},\"group\":[\"hour\",\"time_stamp\",\"aff_id\"],\"settings\":{\"time\":{\"start\":1399942800,\"end\":1399946399,\"timezone\":0},\"data_source\":\"contrack_druid_datasource_ds\",\"pagination\":{\"size\":10000,\"page\":0}}}";
        String url_str = "http://10.1.5.11/report";
        
        String parameters_str = "report_param={\"data\":[\"clicks\"],\"filters\":{\"$and\":{\"campaign_id\":{\"$eq\":201405}}},\"group\":[\"hour\",\"time_stamp\",\"aff_id\"],\"settings\":{\"time\":{\"start\":1399942800,\"end\":1399946399,\"timezone\":0},\"data_source\":\"contrack_druid_datasource_ds\",\"pagination\":{\"size\":10000,\"page\":0}}}";
        URL url = new URL(url_str); // http://www.druid.broker:8080/druid/v2/?pretty
        URLConnection urlConnection = url.openConnection();
        urlConnection.addRequestProperty("content-type", "application/json");
        urlConnection.setDoOutput(true);
        urlConnection.getOutputStream().write(parameters_str.getBytes(Charsets.UTF_8));
        // BufferedReader stdInput = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        InputStream csvInputStream = urlConnection.getInputStream();
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        AmazonS3 conn = new AmazonS3Client(credentials);
        // System.out.println(conn.putObject("druid.yeahmobi.com", "/dst_dir/csv/" + "key_mkd5" + ".csv.gz", csvInputStream, new ObjectMetadata()));
        // InputStream inputStream = AmazonS3IO.getS3ObjectInputStream(conn, fileName, srcBucket, srcDir);
    }
}
